/**
 * 编辑器核心逻辑 - 符合utility.mdr规则
 */
import { ICircuitElement } from '../circuit-elements.js';
import { editorTokenManager } from '../globalMgr.js';

export class EditorCore {
    private elements: ICircuitElement[] = [];
    private selectedTool: string | null = null;

    constructor() {
        this.setupEventListeners();
    }

    addElement(element: ICircuitElement, token?: any): boolean {
        if (!editorTokenManager.verifyToken(token?.id)) return false;
        this.elements.push(element);
        this.dispatchEvent('element-added', { element });
        return true;
    }

    setTool(toolId: string): void {
        this.selectedTool = toolId;
        this.dispatchEvent('tool-changed', { toolId });
    }

    private dispatchEvent(type: string, detail: any): void {
        window.dispatchEvent(new CustomEvent(`circuit-editor:${type}`, { detail }));
    }

    private setupEventListeners(): void {
        // 预留事件监听
    }
}